{extend name="public/base"/}
{block name="body"}
<link href="/static/css/common.css" type="text/css" rel="stylesheet">
<link href="/static/css/index.css" type="text/css" rel="stylesheet">
<title>添加分类</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
        <input type="hidden" class="f_id" name="f_id" value="{$f_id}">
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">分类名</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" id="catename" name="catename">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">类别简介</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" id="intro" name="intro">
			</div>
		</div>
		<!-- <div class="row cl">
			<label class="form-label col-xs-3 col-sm-2">图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
                <div style="position:relative;" id="drop_area"></div>
                <p style="color:#ccc;font-size:12px;">建议尺寸宽高:2:1</p>
			</div>
		</div> -->
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>

<script type="text/javascript" src="/static/lib/jquery/1.9.1/jquery.min.js"></script> 

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/jquery.validate.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/validate-methods.js"></script> 
<script type="text/javascript" src="/static/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="/static/js/upload.js"></script>
<script type="text/javascript">
var icon;
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	$("#form-admin-add").validate({
		rules:{
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "{:url('cate_add')}",
				data:{icon:icon},
				success: function(data){
					if(data.code==200){
						layer.msg('成功！',{icon:1,time:3000});
						setTimeout("parent.location.reload()",1000);
					}else{
						layer.msg(data.msg,{icon:2,time:3000});
					}

				},
                error: function(){
					layer.msg('数据保存失败',{icon:2,time:3000});
				}
			});
		}
	});
});
var dragImgUpload = new DragImgUpload("#drop_area",{
    callback:function (files) {
        //回调函数，可以传递给后台等等
        if(files[0].size<3145728){
	        var file = files[0];
	        var formData = new FormData();
	        formData.append("file",file);
	        $.ajax({
	              type: 'POST',
	              url: "{:url('uploadtmd')}",
	              data:formData,
	              contentType: false, /*不可缺*/
	              processData: false, /*不可缺*/
	              success: function(response){
	                if(response.code==200){
	                  icon=response.photo
	                }else{
	                  alert(response.msg);
	                }
	              },
	              error: function(err){

	              }
	        })
        }else{
        	alert('出错');
        	location.replace(location.href);
        }
    }
});
</script> 
{/block}